home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / programm / gemfsc19 / gemfsc19.lzh / GEMFUNCS / LCBUG.C < prev    next >
C/C++ Source or Header  |  1993-05-08  |  2KB  |  45 lines

  1.  
  2.  In setting up my gemfast libraries to work in all memory models, I've run
  3. across what looks like a bug in handling __saveds in prototypes.  If a 
  4. base-relative memory model is in use, any declaration of a function pointer
  5. argument in a prototype that includes __saveds will give an argument type
  6. mismatch error when you try to pass a function name as a function pointer.
  7.  
  8.  Different compilers and memory models need different options for defining
  9. a G_USERDEF drawing function.  For portability between compilers, I define
  10. a GCALLBACK macro with the keywords the host compiler needs.  For LC, that
  11. means "far __stdargs __saveds".  This macro is used both to define the 
  12. function, and to declare arguments in prototypes where I sometimes pass
  13. pointers to G_USERDEF functions around.  Stripping out a lot of gemfast
  14. internals smoke-and-mirrors, here's a little demo of the problem... 
  15.  
  16. #define GCALLBACK far __stdargs __saveds
  17.  
  18. typedef void GCALLBACK (GCALLBACKFUNC)(void);
  19.  
  20. extern void yfunc(GCALLBACKFUNC *);
  21.  
  22. static void GCALLBACK xfunc(void) 
  23. {
  24.     return;
  25. }
  26.  
  27. void main(void)
  28. {
  29.     yfunc(xfunc); // <-- xfunc flagged as "argument type incorrect"
  30. }
  31.  
  32.  The LC manual says __saveds is ignored in external declarations, but
  33.  apparently it is neither ignored nor handled properly in argument 
  34.  declarations within prototypes.  Interestingly, if you leave the __saveds
  35.  out of the argument in the prototype, but use it in defining the function,
  36.  you *don't* get a type mismatch.  (Which is fine I guess, since it affects
  37.  only the codegen at definition time, but not how the function is called.)
  38.  
  39.  I've discovered a klugey workaround, wherein I just #define __saveds to
  40.  nothingness before my big block of prototypes in gemfast.h, then #undef
  41.  it at the end of the header (so that it will be in effect during function
  42.  definitions in modules that #include <gemfast.h>), but such a workaround
  43.  shouldn't really be necessary.
  44.  
  45.